How to call one jsp page to another jsp page on click of a button?
This was the question that one of my colleage asked me hrs back .
Suppose you have a index.jsp page and you want to call a target.jsp ,
we can create a html button and call a javaScript onclick event.
provide action as the target jsp name and submit the page.
here is the index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!--<span class="hiddenSpellError" pre=""-->DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <script type="text/javascript"> function submitx(){ alert('x'); document.forms[0].action='target.jsp'; document.forms[0].submit(); } </script> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <form><input type="button" value="Submit" onclick="submitx()"></form> </body> </html>
here is the target.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> target </body> </html>
Leave a comment